export default {

  data() {
    return {
      cxfbLabel: '城乡分布(在校生)',
      sqznLabel: '随迁子女',
      curMenuId: 1,
      studentMenuId: '',
      studentchart1: null,
      studentchart2: null,
      studentchart3: null,
      studentoption1: {},
      studentoption2: {},
      studentoption3: {},
      stuQuery: ['学前教育', '小学', '初中', '高中', '中职', '特殊教育', '总计'],
      studatabyqs: [],
      studatacxfb: [],
      studatasqzn: [],
      tjHeight: '300px'
    }
  },

  computed: {
    tjmarginTop () {
      let m = '0'
      this.tjHeight = '400px'
      if (this.curMenuId === 6 && this.page === 'student') {
        m = '180px'
        this.tjHeight = '500px'

        return m
      } else {
        return m
      }
    }
  },

  methods: {
    initStu () {
      if (!this.studentchart1) {
        this.studentchart1 = window.echarts.init(this.$refs.chartstudent1)
        this.studentchart2 = window.echarts.init(this.$refs.chartstudent2)
        this.studentchart3 = window.echarts.init(this.$refs.chartstudent3)
      }
      this.getStudentData()
    },

    setOptionstu () {
      let vm = this
      if (vm.curMenuId === 1) { // 学前数据替换
        vm.sqznLabel = '普惠统计'
      } else if (vm.curMenuId === 5) { // 中职数据替换
        vm.cxfbLabel = '在校生数分科类统计'
        vm.sqznLabel = '中职生占高中阶段比例'
      } else {
        vm.cxfbLabel = '城乡分布(在校生)'
        vm.sqznLabel = '随迁子女'
      }
      vm.$nextTick(() => {
        if (vm.studatabyqs.length > 0) {
          vm.getByqsData(vm.studatabyqs[vm.curMenuId - 1])
        } else {
          vm.getByqsData([])
        }
        if (vm.studatacxfb.length > 0) {
          vm.getCxfbData(vm.studatacxfb[vm.curMenuId - 1])
        } else {
          vm.getCxfbData([])
        }
        if (vm.studatacxfb.length > 0) {
          vm.getSqznData(vm.studatasqzn[vm.curMenuId - 1])
        } else {
          vm.getSqznData([])
        }
      })
    },
    getStudentData () {
      let vm = this

      let getwayurl = window.$twApp.gateway
      if (this.baseurls.length > 0 && this.baseurls[0].indexOf('http:') > -1) {
        getwayurl = this.baseurls[0]
      }
      let url = getwayurl + '/tw-cloud-datatheme-server/themedata/dp_xsgk'
      let quary = { 'conditions': [{ "fieldName": "jgid", "operator": "IN", "fieldValues": ["430100000000"], "prepender": "AND"}], 'fields': [], 'orderMethods': [] }
      let orderMethods = { 'field': 'tjnf', 'method': 'ASC' }
      quary.orderMethods.push(orderMethods)

      vm.studatabyqs = []
      vm.studatacxfb = []
      vm.studatasqzn = []
      let legend = ['趋势数据', '毕业', '在校', '招生']
      let legendcx = ['城乡分布数据', '城区', '镇区', '乡村']
      let legendcx1 = ['分科类统计数据', '农林牧副渔类', '资源环境类', '能源与新能源类', '土木水利类', '加工制造类', '石油化工类', '轻纺食品类', '交通运输类', '信息技术类', '医药卫生类', '休闲保健类', '财经商贸类', '旅游服务类', '文化艺术类', '体育与健身', '教育类', '司法服务类', '公共管理与服务类', '其他']
      let legendsq = ['随迁子女数据', '随迁子女数量']
      let legendsq1 = ['普惠统计数据', '公办园在园幼儿比率(长沙)', '普惠性幼儿园覆盖率(长沙)'] //  '公办园在园幼儿比率(全国)',
      let legendsq2 = ['中职生高中阶段占比', '招生数占比(长沙)', '在校生占比(长沙)'] // , '招生数占比(全省)', '在校生占比(全省)', '招生数占比(全国)', '在校生占比(全国)'
      window.axios.post(url, quary).then(res => {
        if (res.data && res.data.pageInfo && res.data.pageInfo.list.length > 0) {
          let xqqsdata = []
          let xxqsdata = []
          let czqsdata = []
          let gzqsdata = []
          let zzqsdata = []
          let tjqsdata = []

          let xqcxdata = []
          let xxcxdata = []
          let czcxdata = []
          let gzcxdata = []
          let zzcxdata = []
          let tjcxdata = []

          let xqsqdata = []
          let xxsqdata = []
          let czsqdata = []
          let gzsqdata = []
          let zzsqdata = []
          let tjsqdata = []
          res.data.pageInfo.list.forEach((item, index) => {
            if (index === 0) {
              xqqsdata.push(legend)
              xxqsdata.push(legend)
              czqsdata.push(legend)
              gzqsdata.push(legend)
              zzqsdata.push(legend)
              tjqsdata.push(legend)

              xqcxdata.push(legendcx)
              xxcxdata.push(legendcx)
              czcxdata.push(legendcx)
              gzcxdata.push(legendcx)
              zzcxdata.push(legendcx1)
              tjcxdata.push(legendcx)

              xqsqdata.push(legendsq1)
              xxsqdata.push(legendsq)
              czsqdata.push(legendsq)
              gzsqdata.push(legendsq)
              zzsqdata.push(legendsq2)
              tjsqdata.push(legendsq)
            }
            let xqqs = [item.tjnf, item.xqjy_byss, item.xqjy_zxss, item.xqjy_zss]
            let xxqs = [item.tjnf, item.xx_byss, item.xx_zxss, item.xx_zss]
            let czqs = [item.tjnf, item.cz_byss, item.cz_zxss, item.cz_zss]
            let gzqs = [item.tjnf, item.gz_byss, item.gz_zxss, item.gz_zss]
            let zzqs = [item.tjnf, item.zz_byss, item.zz_zxss, item.zz_zss]
            let tjqs = [item.tjnf, item.tsjy_byss, item.tsjy_zxss, item.tsjy_zss]

            let xqcx = [item.tjnf, item.xqjy_zxss_cq, item.xqjy_zxss_zq, item.xqjy_zxss_xc]
            let xxcx = [item.tjnf, item.xx_zxss_cq, item.xx_zxss_zq, item.xx_zxss_xc]
            let czcx = [item.tjnf, item.cz_zxss_cq, item.cz_zxss_zq, item.cz_zxss_xc]
            let gzcx = [item.tjnf, item.gz_zxss_cq, item.gz_zxss_zq, item.gz_zxss_xc]
            let zzcx = [item.tjnf, item.zz_kl_nlmyl, item.zz_kl_zyhjl, item.zz_kl_nyyxnyl, item.zz_kl_tmsll, item.zz_kl_jgzzl, item.zz_kl_syhgl, item.zz_kl_qfspl, item.zz_kl_jtysl, item.zz_kl_xxjsl, item.zz_kl_cjsml, item.zz_kl_nyfwl, item.zz_kl_whysl, item.zz_kl_tyyjs, item.zz_kl_yjl, item.zz_kl_sffwl, item.zz_kl_ggglyfwl, item.zz_kl_qt]
            let tjcx = [item.tjnf, item.tsjy_zxss_cq, item.tsjy_zxss_zq, item.tsjy_zxss_xc, item.zz_kl_yywsl, item.zz_kl_xxbjl]

            let xqsq = [item.tjnf, item.xqjy_gbyeyzy_zbl, item.xqjy_mb_phxmbyey_fgl]
            let xxsq = [item.tjnf, item.xx_zxss_sqzn]
            let czsq = [item.tjnf, item.cz_zxss_sqzn]
            let gzsq = [item.tjnf, item.gz_zxss_sqzn]
            let zzsq = [item.tjnf, item.zz_gzjd_zss_zb, item.zz_gzjd_zxss_zb]
            let tjsq = [item.tjnf, item.tsjy_zxss_sqzn]

            xqqsdata.push(xqqs)
            xxqsdata.push(xxqs)
            czqsdata.push(czqs)
            gzqsdata.push(gzqs)
            zzqsdata.push(zzqs)
            tjqsdata.push(tjqs)

            xqcxdata.push(xqcx)
            xxcxdata.push(xxcx)
            czcxdata.push(czcx)
            gzcxdata.push(gzcx)
            zzcxdata.push(zzcx)
            tjcxdata.push(tjcx)

            xqsqdata.push(xqsq)
            xxsqdata.push(xxsq)
            czsqdata.push(czsq)
            gzsqdata.push(gzsq)
            zzsqdata.push(zzsq)
            tjsqdata.push(tjsq)
          })
          vm.studatabyqs.push(xqqsdata)
          vm.studatabyqs.push(xxqsdata)
          vm.studatabyqs.push(czqsdata)
          vm.studatabyqs.push(gzqsdata)
          vm.studatabyqs.push(zzqsdata)
          vm.studatabyqs.push(tjqsdata)

          vm.studatacxfb.push(xqcxdata)
          vm.studatacxfb.push(xxcxdata)
          vm.studatacxfb.push(czcxdata)
          vm.studatacxfb.push(gzcxdata)
          vm.studatacxfb.push(zzcxdata)
          vm.studatacxfb.push(tjcxdata)

          vm.studatasqzn.push(xqsqdata)
          vm.studatasqzn.push(xxsqdata)
          vm.studatasqzn.push(czsqdata)
          vm.studatasqzn.push(gzsqdata)
          vm.studatasqzn.push(zzsqdata)
          vm.studatasqzn.push(tjsqdata)
        }
        vm.setOptionstu()
      }).catch(err => {
        console.error(err)
        vm.setOptionstu()
      })
    },
    getByqsData (indata) {
      let vm = this
      let data = indata
      if (data.length === 0) {
        data = [
          ['数据', '毕业', '在校', '招生'],
          ['2015', 0, 0, 0],
          ['2016', 0, 0, 0],
          ['2017', 0, 0, 0],
          ['2018', 0, 0, 0],
          ['2019', 0, 0, 0],
        ]
      }
      let length = data[0].length

      this.studentoption1 = JSON.parse(JSON.stringify(this.option))
      let a = this.studentoption1.dataset
      let b = this.studentoption1.grid
      let tt = this.studentoption1.tooltip
      tt.formatter = function (params) {
        let text = ''
        params.forEach((item, index) => {
          if (index === 0) {
            text += item.name + '<br>'
          } else {
            text += '<br>'
          }
          if (!item.value[item.componentIndex + 1] || item.value[item.componentIndex + 1] + '' === 'undefined' || item.value[item.componentIndex + 1] + '' === 'NAN') {
            text += item.marker + item.seriesName + '0人'
          } else {
            let v = Math.round(item.value[item.componentIndex + 1] * 100) / 100
            text += item.marker + item.seriesName + v + '人'
          }
        })
        return text
      }
      b.left = '18%'
      a.source = data
      let lt = this.studentoption1.legend.textStyle
      lt.fontSize = 16
      let xt = this.studentoption1.xAxis.axisLabel.textStyle
      xt.fontSize = 16
      let yt = this.studentoption1.yAxis.axisLabel.textStyle
      yt.fontSize = 16
      let ya = this.studentoption1.xAxis.axisLabel
      ya.formatter = '{value}年'
      let tmpxAxis = this.studentoption1.xAxis
      tmpxAxis.boundaryGap = false
      this.studentoption1.series = []
      for (let i = 0; i < length - 1; i++) {
        this.studentoption1.series.push({
          type: 'line',
          // stack: 'stack',
          lineStyle: {
            width: 4
          },
          symbolSize: 8,
          areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
              offset: 0,
              color: 'rgba(74,199,255,0)'
            }, {
              offset: 1,
              color: 'rgba(74,199,255,0.35)'
            }])
          }
        })
      }

      this.studentchart1.setOption(this.studentoption1, true)
    },
    getCxfbData (indata) {
      let vm = this
      let data = indata
      if (data.length === 0) {
        data = [
          ['数据', '城区', '镇区', '乡村'],
          ['2015', 0, 0, 0],
          ['2016', 0, 0, 0],
          ['2017', 0, 0, 0],
          ['2018', 0, 0, 0],
          ['2019', 0, 0, 0],
        ]
      }
      let length = data[0].length

      this.studentoption2 = JSON.parse(JSON.stringify(this.option))
      let a = this.studentoption2.dataset
      let b = this.studentoption2.grid
      let ya = this.studentoption2.xAxis.axisLabel
      ya.formatter = '{value}年'
      b.left = '15%'
      b.right = '5%'
      if (vm.curMenuId === 5) {
        b.top = '25%'
        // let tmpxAxis = this.studentoption2.xAxis
        // tmpxAxis.boundaryGap = true
      }
      a.source = data
      let tt = this.studentoption2.tooltip

      tt.formatter = function (params) {
        let text = ''
        let unit = '在校人数'
        if (vm.curMenuId === 5) {
          unit = ''
        }
        params.forEach((item, index) => {
          if (index === 0) {
            text += item.name + '<br>'
          } else {
            text += '<br>'
          }
          if (!item.value[item.componentIndex + 1] || item.value[item.componentIndex + 1] + '' === 'undefined' || item.value[item.componentIndex + 1] + '' === 'NAN') {
            text += item.marker + item.seriesName + unit + '0人'
          } else {
            let v = Math.round(item.value[item.componentIndex + 1] * 100) / 100
            text += item.marker + item.seriesName + unit + v + '人'
          }
        })
        return text
      }

      let lt = this.studentoption2.legend.textStyle
      lt.fontSize = 10
      let xt = this.studentoption2.xAxis.axisLabel.textStyle
      xt.fontSize = 16
      let yt = this.studentoption2.yAxis.axisLabel.textStyle
      yt.fontSize = 16
      this.studentoption2.series = []
      for (let i = 0; i < length - 1; i++) {
        this.studentoption2.series.push({
          type: vm.curMenuId === 5 ? 'line' : 'bar',
          barMaxWidth: 28
        })
      }

      this.studentchart2.setOption(this.studentoption2, true)
      this.studentchart2.resize()
    },
    getSqznData (indata) {
      let vm = this
      let data = indata
      if (data.length === 0) {
        data = [
          ['数据', '数据'],
          ['2015', 0],
          ['2016', 0],
          ['2017', 0],
          ['2018', 0],
          ['2019', 0],
        ]
      }
      let length = data[0].length

      this.studentoption3 = JSON.parse(JSON.stringify(this.option))
      let a = this.studentoption3.dataset
      let b = this.studentoption3.grid
      b.left = '15%'
      b.right = '5%'
      a.source = data
      if (this.curMenuId !== 1 && this.curMenuId !== 5) {
        let c = this.studentoption3.legend
        c.show = false
      }
      let lt = this.studentoption3.legend.textStyle
      lt.fontSize = 16
      let xt = this.studentoption3.xAxis.axisLabel.textStyle
      xt.fontSize = 16
      let yt = this.studentoption3.yAxis.axisLabel.textStyle
      yt.fontSize = 16
      let ya = this.studentoption3.xAxis.axisLabel
      ya.formatter = '{value}年'
      let tmpxAxis = this.studentoption3.xAxis
      tmpxAxis.boundaryGap = false
      let tt = this.studentoption3.tooltip

      tt.formatter = function (params) {
        let text = ''
        let unit = '人'
        if (vm.curMenuId === 1 || vm.curMenuId === 5) {
          unit = '%'
        }
        params.forEach((item, index) => {
          if (index === 0) {
            text += item.name + '<br>'
          } else {
            text += '<br>'
          }
          if (!item.value[item.componentIndex + 1] || item.value[item.componentIndex + 1] + '' === 'undefined' || item.value[item.componentIndex + 1] + '' === 'NAN') {
            text += item.marker + item.seriesName + '0' + unit
          } else {
            let v = Math.round(item.value[item.componentIndex + 1] * 100) / 100
            text += item.marker + item.seriesName + v + unit
          }
        })
        return text
      }
      this.studentoption3.series = []
      for (let i = 0; i < length - 1; i++) {
        this.studentoption3.series.push({
          type: 'line',
          lineStyle: {
            width: 4
          },
          symbolSize: 8,
          areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
              offset: 0,
              color: 'rgba(74,199,255,0)'
            }, {
              offset: 1,
              color: 'rgba(74,199,255,0.35)'
            }])
          }
        })
      }

      this.studentchart3.setOption(this.studentoption3, true)
    },
  },

  mounted () {

  },

  beforeDestroy () {
    if (this.studentchart1) {
      this.studentchart1.dispose()
      this.studentchart1 = null
      this.studentchart2.dispose()
      this.studentchart2 = null
      this.studentchart3.dispose()
      this.studentchart3 = null
    }
  },

  watch: {

  }
}
